﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Common.Logging.Loupe.Test
{
    [TestClass]
    public class ParsableEnumTest
    {
        [TestMethod]
        public void CachedString()
        {
            string name1 = Enum.GetName(typeof(LogLevel), LogLevel.Info);
            string name2 = ParsableEnum<LogLevel>.ToCachedString(LogLevel.Info);

            Assert.AreEqual(name1, name2, "ToString() names did not match.");
        }

        [TestMethod]
        public void TryParse()
        {
            LogLevel level;
            bool didParse = ParsableEnum<LogLevel>.TryParse("Info", out level);
            Assert.IsTrue(didParse, "TryParse reported false for a valid value");
            Assert.AreEqual(LogLevel.Info, level, "Parsed value did not match expected.");
        }

        [TestMethod]
        public void TryParseFail()
        {
            LogLevel level;
            bool didParse = ParsableEnum<LogLevel>.TryParse("In2o", out level);
            Assert.IsFalse(didParse, "TryParse reported true for an invalid value");
        }
    }
}
